﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="EditItemsSuppliers.aspx.cs" Inherits="Items_Items" Title="Добави Нов Продукт" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<br />
    <table class="style1">
        <tr>
            <td>
        <asp:DetailsView ID="dvItems" runat="server" AutoGenerateRows="False" 
        DataKeyNames="ItemID" DataSourceID="sdsItems" DefaultMode="Edit" 
        Height="50px" Width="380px" BackColor="White" BorderColor="#DEDFDE" 
        BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" 
        GridLines="Vertical" oniteminserted="dvItems_ItemInserted" 
                    onitemupdated="dvItems_ItemUpdated">
        <FooterStyle BackColor="#CCCC99" />
        <RowStyle BackColor="#F7F7DE" />
        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
        <Fields>
            <asp:BoundField DataField="ItemCode" HeaderText="Код на продукта" 
                SortExpression="ItemCode" />
            <asp:BoundField DataField="NameBG" HeaderText="Име БГ" 
                SortExpression="NameBG" />
            <asp:BoundField DataField="NameEN" HeaderText="Име EN" 
                SortExpression="NameEN" />
            <asp:TemplateField HeaderText="Доставчик" SortExpression="SupplierID">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("SupplierID") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="ddlSuppliers" runat="server" DataSourceID="sdsSuppliers" 
                        DataTextField="Name" DataValueField="SupplierID">
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("SupplierID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Клиент" SortExpression="CustomerID">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CustomerID") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="ddlCustomers" runat="server" DataSourceID="sdsCustomers" 
                        DataTextField="Name" DataValueField="CustomerID">
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("CustomerID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="EXW ЦЕНА">
                <HeaderStyle BackColor="Black" />
            </asp:TemplateField>
            <asp:BoundField DataField="EXW1" HeaderText="EXW в ЛВ без обков" 
                SortExpression="EXW1" />
            <asp:BoundField DataField="EXW2" HeaderText="EXW цена на обкова в ЛВ" 
                SortExpression="EXW2" />
            <asp:BoundField DataField="EXW3" HeaderText="EXW цена в ЛВ с обков" 
                SortExpression="EXW3" />
            <asp:TemplateField HeaderText="DDU ЦЕНА">
                <FooterStyle BackColor="Black" />
                <HeaderStyle BackColor="Black" />
            </asp:TemplateField>
            <asp:BoundField DataField="DDU1_EUR" HeaderText="DDU цена в EUR без обков" 
                SortExpression="DDU1_EUR" />
            <asp:BoundField DataField="DDU2_EUR" HeaderText="DDU цена на обкова в EUR" 
                SortExpression="DDU2_EUR" />
            <asp:BoundField DataField="DDUEUR" HeaderText="DDU цена с обков в EUR" 
                SortExpression="DDUEUR" />
            <asp:BoundField DataField="DDUBGN" HeaderText="DDU цена с обков в ЛВ" 
                SortExpression="DDUBGN" />
            <asp:BoundField DataField="Count1" HeaderText="Бр. в Комплект" SortExpression="Count1" />
            <asp:BoundField DataField="Count2" HeaderText="Комплекти в Кашон" SortExpression="Count2" />
            <asp:BoundField DataField="Count3" HeaderText="Кашон в Палет" SortExpression="Count3" />
            <asp:BoundField DataField="Count4" HeaderText="Комплекти в Палет" SortExpression="Count4" />
            <asp:CommandField CancelText="Прекъсни" EditText="Редактирай" 
                ShowEditButton="True" UpdateText="Обнови" />
        </Fields>
        <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <HeaderTemplate>
            Добавяне на нов продукт
        </HeaderTemplate>
        <EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:DetailsView>
            </td>
            <td>
<asp:GridView ID="gvItem" runat="server" AllowPaging="True" 
                    BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
                    CellPadding="4" DataKeyNames="ItemID" DataSourceID="sdsItem" ForeColor="Black" 
                    GridLines="Vertical" AutoGenerateColumns="False" 
                    onselectedindexchanged="gvItem_SelectedIndexChanged" >
                    <FooterStyle BackColor="#CCCC99" />
                    <RowStyle BackColor="#F7F7DE" />
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" SelectText="Избери" />
                        <asp:BoundField DataField="ItemCode" HeaderText="Код" 
                            SortExpression="ItemCode" />
                        <asp:BoundField DataField="NameBG" HeaderText="Име БГ" 
                            SortExpression="NameBG" />
                        <asp:BoundField DataField="NameEN" HeaderText="Име АН" 
                            SortExpression="NameEN" />
                    </Columns>
                    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
                <br />             
 <div>
    <ajaxToolkit:Accordion ID="MyAccordion" runat="server" 
                           SelectedIndex="0" 
                           HeaderCssClass="accordionHeader" 
                           ContentCssClass="accordionContent" 
                           FadeTransitions="true" 
                           FramesPerSecond="40" 
                           TransitionDuration="250"
                           AutoSize="None">
     <Panes>
        <ajaxToolkit:AccordionPane ID = "AccordionPane1" runat = "server">
          <Header>
            <a href = "" onclick = "return false;" class = "accordionLink">Платове</a>
          </Header>
          <Content>
                   <asp:GridView ID="gvBufabs" runat="server" AllowPaging="True"   
                    BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
                    CellPadding="4" DataKeyNames="BufabMaterialID" DataSourceID="sdsBufabs" 
                    ForeColor="Black" GridLines="Vertical" AutoGenerateColumns="False" 
                    onselectedindexchanged="gvBufabs_SelectedIndexChanged">
                    <FooterStyle BackColor="#CCCC99" />
                    <RowStyle BackColor="#F7F7DE" />
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" SelectText="Добави Обков " />
                        <asp:BoundField DataField="ArticleNo" HeaderText="Код" SortExpression="ArticleNo" />                  
                        <asp:BoundField DataField="Article" HeaderText="Име" SortExpression="Article" />                  
                        <asp:BoundField DataField="Description" HeaderText="Описание" SortExpression="Description" />                  
                        <asp:BoundField DataField="Price" HeaderText="Цена" SortExpression="Price" />                  
                    </Columns>
                    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
          </Content>
        </ajaxToolkit:AccordionPane>
        <ajaxToolkit:AccordionPane ID = "AccordionPane2" runat = "server">
          <Header>
            <a href = "" onclick = "return false;" class = "accordionLink"> Обкови</a>
          </Header>
          <Content>
            <asp:GridView ID="gvMaterials" runat="server" AllowPaging="True"   
                    BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
                    CellPadding="4" DataKeyNames="BufabMaterialID" DataSourceID="sdsMaterials" 
                    ForeColor="Black" GridLines="Vertical" AutoGenerateColumns="False" 
                    onselectedindexchanged="gvMaterials_SelectedIndexChanged">
                    <FooterStyle BackColor="#CCCC99" />
                    <RowStyle BackColor="#F7F7DE" />
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" SelectText="Добави Плат" />
                        <asp:BoundField DataField="ArticleNo" HeaderText="Код" SortExpression="ArticleNo" />                  
                        <asp:BoundField DataField="Article" HeaderText="Име" SortExpression="Article" />                  
                        <asp:BoundField DataField="Description" HeaderText="Описание" SortExpression="Description" />                  
                        <asp:BoundField DataField="Price" HeaderText="Цена" SortExpression="Price" />                  
                    </Columns>
                    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>    
          </Content>
        </ajaxToolkit:AccordionPane>
     </Panes>
     </ajaxToolkit:Accordion>
    </div>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>Списък на обковите<br />
                <asp:GridView ID="gvBufabsList" runat="server" BackColor="White" 
                    BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
                    ForeColor="Black" GridLines="Horizontal" DataSourceID="sdsBufabList" 
                    AutoGenerateColumns="False" DataKeyNames="FinalProductID">
                    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                    <Columns>
                        <asp:CommandField DeleteText="Изтрий" ShowDeleteButton="True" />
                        <asp:BoundField DataField="ArticleNo" HeaderText="Код" 
                            SortExpression="ArticleNo" />
                        <asp:BoundField DataField="Article" HeaderText="Име" 
                            SortExpression="Article" />
                        <asp:BoundField DataField="Description" HeaderText="Описание" 
                            SortExpression="Description" />
                        <asp:BoundField DataField="Price" HeaderText="Цена" 
                            SortExpression="Price" />
                    </Columns>
                    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
                </asp:GridView>
                <br />
            </td>
            <td>Списък на платовете<br />
                <asp:GridView ID="gvMaterialsList" runat="server" BackColor="White" 
                    BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
                    ForeColor="Black" GridLines="Horizontal" DataSourceID="sdsMaterialsList" 
                    AutoGenerateColumns="False" DataKeyNames="FinalProductID">
                    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                    <Columns>
                        <asp:CommandField DeleteText="Изтрий" ShowDeleteButton="True" />
                        <asp:BoundField DataField="ArticleNo" HeaderText="Код" 
                            SortExpression="ArticleNo" />
                        <asp:BoundField DataField="Article" HeaderText="Име" 
                            SortExpression="Article" />
                        <asp:BoundField DataField="Description" HeaderText="Описание" 
                            SortExpression="Description" />
                        <asp:BoundField DataField="Price" HeaderText="Цена" 
                            SortExpression="Price" />
                    </Columns>
                    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
                </asp:GridView>
            </td>
        </tr>
    </table>

    <asp:SqlDataSource ID="sdsItems" runat="server" 
        ConflictDetection="CompareAllValues" 
        ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
        InsertCommand="INSERT INTO [Items] ([ItemCode], [NameBG], [NameEN], [CustomerID], [SupplierID], [EXW1], [EXW2], [EXW3],  [DDU1_EUR], [DDU2_EUR], [DDUEUR], [DDUBGN], [Count1], Count2, Count3, Count4) VALUES (@ItemCode, @NameBG, @NameEN, @CustomerID, @SupplierID, @EXW1, @EXW2, @EXW3,  @DDU1_EUR, @DDU2_EUR, @DDUEUR, @DDUBGN, @Count1, @Count2,@Count3, @Count4)" 
        OldValuesParameterFormatString="original_{0}" 
        
        SelectCommand="SELECT [ItemID], [ItemCode], [NameBG], [NameEN], [CustomerID], [SupplierID], [EXW1], [EXW2], [EXW3], [DDU1_EUR], [DDU2_EUR], [DDUEUR], [DDUBGN], Count1, Count2, Count3, Count4  FROM [Items] Where (ItemID = @ItemID)" 
        UpdateCommand="UPDATE [Items] SET [ItemCode] = @ItemCode, [NameBG] = @NameBG, [NameEN] = @NameEN, [CustomerID] = @CustomerID, [SupplierID] = @SupplierID, [EXW1] = @EXW1, [EXW2] = @EXW2, [EXW3] = @EXW3, [DDU1_EUR] = @DDU1_EUR, [DDU2_EUR] = @DDU2_EUR, [DDUEUR] = @DDUEUR, [DDUBGN] = @DDUBGN, [Count1] = @Count1, [Count2] = @Count2, [Count3] = @Count3, [Count4] = @Count4 WHERE [ItemID] = @original_ItemID">
        <SelectParameters>
            <asp:ControlParameter ControlID="gvItem" Name="ItemID" 
                PropertyName="SelectedValue" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="ItemCode" />
            <asp:Parameter Name="NameBG" />
            <asp:Parameter Name="NameEN" />
            <asp:Parameter Name="CustomerID" />
            <asp:Parameter Name="SupplierID" />
            <asp:Parameter Name="EXW1" />
            <asp:Parameter Name="EXW2" />
            <asp:Parameter Name="EXW3" />
            <asp:Parameter Name="DDU1_EUR" />
            <asp:Parameter Name="DDU2_EUR" />
            <asp:Parameter Name="DDUEUR" />
            <asp:Parameter Name="DDUBGN" />
            <asp:Parameter Name="Count1" />
            <asp:Parameter Name="Count2" />
            <asp:Parameter Name="Count3" />
            <asp:Parameter Name="Count4" />
            <asp:Parameter Name="original_ItemID" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="ItemCode" Type="String" />
            <asp:Parameter Name="NameBG" Type="String" />
            <asp:Parameter Name="NameEN" Type="String" />
            
            <asp:ControlParameter Name="CustomerID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvItems$ddlCustomers" PropertyName="SelectedValue" />
            <asp:ControlParameter Name="SupplierID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvItems$ddlSuppliers" PropertyName="SelectedValue" />
           
            <asp:Parameter Name="EXW1" Type="Decimal" />
            <asp:Parameter Name="EXW2" Type="Decimal" />
            <asp:Parameter Name="EXW3" Type="Decimal" />
            <asp:Parameter Name="DDU1_EUR" Type="Decimal" />
            <asp:Parameter Name="DDU2_EUR" Type="Decimal" />
            <asp:Parameter Name="DDUEUR" Type="Decimal" />
            <asp:Parameter Name="DDUBGN" Type="Decimal" />
            <asp:Parameter Name="Count1" />
            <asp:Parameter Name="Count2" />
            <asp:Parameter Name="Count3" />
            <asp:Parameter Name="Count4" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsMaterials" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
        SelectCommand="SELECT BufabMaterialID, ArticleNo, Article, Description, Price, IsBufab FROM BufabMaterials Where IsBufab = 'False'">
   </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsCustomers" runat="server" 
        ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
        SelectCommand="SELECT CustomerID, Name FROM Customers"></asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsSuppliers" runat="server" 
        ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
        SelectCommand="SELECT SupplierID, Name FROM Suppliers WHERE (SupplierID = @SupplierID)">
        <SelectParameters>
            <asp:QueryStringParameter Name="SupplierID" QueryStringField="SupplierID" />
        </SelectParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="sdsItems0" runat="server" 
        ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
        InsertCommand="INSERT INTO [Items] ([ItemCode], [NameBG], [NameEN], [CustomerID], [SupplierID], [EXW1], [EXW2], [EXW3], [DDU1_EUR], [DDU2_EUR], [DDUEUR], [DDUBGN], [Count1], [Count2], [Count3], [Count4]) VALUES (@ItemCode, @NameBG, @NameEN, @CustomerID, @SupplierID, @EXW1, @EXW2, @EXW3, @DDU1_EUR, @DDU2_EUR, @DDUEUR, @DDUBGN, @Count1, @Count2, @Count3, @Count4)" 
        OldValuesParameterFormatString="original_{0}" 
        
        SelectCommand="SELECT [ItemID], [ItemCode], [NameBG], [NameEN], [CustomerID], [SupplierID], [EXW1], [EXW2], [EXW3], [DDU1_EUR], [DDU2_EUR], [DDUEUR], [DDUBGN], [Count1], [Count2], [Count3], [Count4] FROM [Items]" 
        DeleteCommand="DELETE FROM [Items] WHERE [ItemID] = @original_ItemID" 
        UpdateCommand="UPDATE [Items] SET [ItemCode] = @ItemCode, [NameBG] = @NameBG, [NameEN] = @NameEN, [CustomerID] = @CustomerID, [SupplierID] = @SupplierID, [EXW1] = @EXW1, [EXW2] = @EXW2, [EXW3] = @EXW3, [DDU1_EUR] = @DDU1_EUR, [DDU2_EUR] = @DDU2_EUR, [DDUEUR] = @DDUEUR, [DDUBGN] = @DDUBGN, [Count1] = @Count1, [Count2] = @Count2, [Count3] = @Count3, [Count4] = @Count4 WHERE [ItemID] = @original_ItemID">
        <DeleteParameters>
            <asp:Parameter Name="original_ItemID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="ItemCode" Type="String" />
            <asp:Parameter Name="NameBG" Type="String" />
            <asp:Parameter Name="NameEN" Type="String" />
            <asp:Parameter Name="CustomerID" Type="Int32" />
            <asp:Parameter Name="SupplierID" Type="Int32" />
            <asp:Parameter Name="EXW1" Type="Decimal" />
            <asp:Parameter Name="EXW2" Type="Decimal" />
            <asp:Parameter Name="EXW3" Type="Decimal" />
            <asp:Parameter Name="DDU1_EUR" Type="Decimal" />
            <asp:Parameter Name="DDU2_EUR" Type="Decimal" />
            <asp:Parameter Name="DDUEUR" Type="Decimal" />
            <asp:Parameter Name="DDUBGN" Type="Decimal" />
            <asp:Parameter Name="Count1" Type="Int32" />
            <asp:Parameter Name="Count2" Type="Int32" />
            <asp:Parameter Name="Count3" Type="Int32" />
            <asp:Parameter Name="Count4" Type="Int32" />
            <asp:Parameter Name="original_ItemID" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="ItemCode" Type="String" />
            <asp:Parameter Name="NameBG" Type="String" />
            <asp:Parameter Name="NameEN" Type="String" />
            
            <asp:ControlParameter Name="CustomerID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvItems$ddlCustomers" PropertyName="SelectedValue" />
            <asp:ControlParameter Name="SupplierID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvItems$ddlSuppliers" PropertyName="SelectedValue" />
           
            <asp:Parameter Name="EXW1" Type="Decimal" />
            <asp:Parameter Name="EXW2" Type="Decimal" />
            <asp:Parameter Name="EXW3" Type="Decimal" />
            <asp:Parameter Name="DDU1_EUR" Type="Decimal" />
            <asp:Parameter Name="DDU2_EUR" Type="Decimal" />
            <asp:Parameter Name="DDUEUR" Type="Decimal" />
            <asp:Parameter Name="DDUBGN" Type="Decimal" />
            <asp:Parameter Name="Count1" />
            <asp:Parameter Name="Count2" />
            <asp:Parameter Name="Count3" />
            <asp:Parameter Name="Count4" />
        </InsertParameters>
    </asp:SqlDataSource>
   <asp:SqlDataSource ID="sdsBufabs" runat="server" 
        ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
       SelectCommand="SELECT BufabMaterialID, ArticleNo, Article, Description, Price, IsBufab FROM BufabMaterials Where IsBufab = 'True'">
   </asp:SqlDataSource>
   <asp:SqlDataSource ID="sdsBufabList" runat="server" 
                    
        ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
        
        SelectCommand="SELECT FinalProducts.FinalProductID, FinalProducts.ItemID, BufabMaterials.ArticleNo, BufabMaterials.Article, BufabMaterials.Description, BufabMaterials.Price, BufabMaterials.IsBufab FROM BufabMaterials INNER JOIN FinalProducts ON BufabMaterials.BufabMaterialID = FinalProducts.BufabMaterialID WHERE (FinalProducts.ItemID = @ItemID) AND (BufabMaterials.IsBufab = 'True')" 
        DeleteCommand="Delete From FinalProducts Where  FinalProducts.FinalProductID = @FinalProductID">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="gvItem" Name="ItemID" 
                            PropertyName="SelectedValue" />
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="FinalProductID" />
                    </DeleteParameters>
                </asp:SqlDataSource>
             
                <asp:SqlDataSource ID="sdsItem" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
                    
        SelectCommand="SELECT ItemID, ItemCode, NameBG, NameEN, SupplierID FROM Items WHERE (SupplierID = @SupplierID)">
                    <SelectParameters>
                        <asp:QueryStringParameter Name="SupplierID" QueryStringField="SupplierID" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="sdsMaterialsList" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
                    
                    
        SelectCommand="SELECT        FinalProducts.FinalProductID, FinalProducts.ItemID, BufabMaterials.ArticleNo, BufabMaterials.Article, BufabMaterials.Description, BufabMaterials.Price, 
                         BufabMaterials.IsBufab
FROM            BufabMaterials INNER JOIN
                         FinalProducts ON BufabMaterials.BufabMaterialID = FinalProducts.BufabMaterialID
WHERE        (FinalProducts.ItemID = @ItemID) AND (BufabMaterials.IsBufab = 'False')" 
        DeleteCommand="Delete From FinalProducts Where  FinalProducts.FinalProductID = @FinalProductID">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="gvItem" Name="ItemID" 
                            PropertyName="SelectedValue" />
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="FinalProductID" />
                    </DeleteParameters>
                </asp:SqlDataSource>
            <asp:SqlDataSource ID="sdsInsFinalProduct" runat="server" 
        ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
        DeleteCommand="DELETE FROM [FinalProducts] WHERE [FinalProductID] = @FinalProductID" 
        InsertCommand="INSERT INTO [FinalProducts] ([ItemID], [BufabMaterialID]) VALUES (@ItemID, @BufabMaterialID)" 
        SelectCommand="SELECT [FinalProductID], [ItemID], [BufabMaterialID] FROM [FinalProducts]" 
        
        
        UpdateCommand="UPDATE [FinalProducts] SET [ItemID] = @ItemID, [BufabMaterialID] = @BufabMaterialID WHERE [FinalProductID] = @FinalProductID">
                <DeleteParameters>
                    <asp:Parameter Name="FinalProductID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="ItemID" Type="Int32" />
                    <asp:Parameter Name="BufabMaterialID" Type="Int32" />
                    <asp:Parameter Name="FinalProductID" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="ItemID" Type="Int32" />
                    <asp:Parameter Name="BufabMaterialID" Type="Int32" />
                </InsertParameters>
    </asp:SqlDataSource>
            </asp:Content>

